package com.numberone.master.common.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class SHA256Str {
		/***
	    *  利用Apache的工具类实现SHA-256加密
	    * @param str 加密后的报文
	    * @return
	    */
	   public static String getSHA256Str(String str){
	       MessageDigest messageDigest;
	       String encdeStr = "";
	       try {
	           messageDigest = MessageDigest.getInstance("SHA-256");
	           byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));
	           encdeStr = Hex.encodeHexString(hash);
	       } catch (NoSuchAlgorithmException e) {
	           e.printStackTrace();
	       } catch (UnsupportedEncodingException e) {
	           e.printStackTrace();
	       }
	       return encdeStr;
	   }
	   public static void main(String[] args) {
		System.out.println(getSHA256Str("admin02NOOC-3IBB78-Y0AG5X-UOQU4P"));
	}
}
